﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CountFeeFrm.aspx.cs" Inherits="WebApp.CountFeeFrm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>费用汇总</title>
    <link rel="stylesheet" type="text/css" href="css/newStyle.css" />
    <link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.3.2/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.3.2/themes/icon.css" />

    <script type="text/javascript" src="js/common.js"></script>

    <script type="text/javascript" src="js/jquery-easyui-1.3.2/jquery-1.8.0.min.js"></script>

    <script type="text/javascript" src="js/jquery-easyui-1.3.2/jquery.easyui.min.js"></script>

    <script type="text/javascript" src="js/jquery-easyui-1.3.2/locale/easyui-lang-zh_CN.js"></script>

    <script type="text/javascript">
        var PageSize = 20;
        //页面加载
        $(window).load(function() {
            initData();
        });

        $(window).resize(function() {
            $('#tb').datagrid('resize');
        });

        function doSearch(pageNumber) {
            if (pageNumber > 0)
                pageNumber = pageNumber - 1; //从0开始
            var params = getParams(pageNumber);
            $('#tb').datagrid('reload', params);
        }


        function getParams(expt) {
            return $.extend({}, {
                DataType: 'CountFee',
                SDate: $('#qSDate').datebox('getValue'),
                EDate: $('#qEDate').datebox('getValue'),
                BizMan: $('#qBizMan').combogrid('getValue')
            });
        }

        function exportExl() {
            var SDate = $('#qSDate').datebox('getValue');
            var EDate = $('#qEDate').datebox('getValue');
            var BizMan = $('#qBizMan').combogrid('getValue');
            if (SDate) {
                if (EDate)
                    window.open("JSONHandler.ashx?Export=true&DataType=CountFee&SDate=" + SDate + "&EDate=" + EDate + "&BizMan=" + BizMan);
            }
        }

        //查询方法
        function doSearch() {
            var validate = $('#fm').form('validate');
            if (!validate)
                return;
            var params = getParams();
            var url = "JSONHandler.ashx";
            //$('#tb').datagrid('reload', params);
            //$.post(url, params, showGrid, "json");

            $.post(url, params, function(data) {

                if (data) {
                    //                    $('#tb').datagrid({
                    //                        loadMsg: '数据加载中请稍后……',
                    //                        //                        columns: [[
                    //                        //                                                { field: '业务员', title: '业务员', align: 'center',width:80 },
                    //                        //                                                { field: '工作单号', title: '工作单号', align: 'center', width: 100 },
                    //                        //                                                { field: '应收(人民币)', title: '应收(人民币)', align: 'center', width: 80 },
                    //                        //                                                { field: '应付(人民币)', title: '应付(人民币)', align: 'center', width: 80 },
                    //                        //                                                { field: '利润(人民币) ', title: '利润(人民币) ', align: 'center', width: 80 },
                    //                        //                                                { field: '应收(美元)', title: '应收(美元)', align: 'center', width: 80 },
                    //                        //                                                { field: '应付(美元)', title: '应付(美元)', align: 'center', width: 80 },
                    //                        //                                                { field: '利润(美元) ', title: '利润(美元)', align: 'center', width: 80 }
                    //                        //                                                ]],
                    //                        //columns: data.columns,
                    //                        //fitColumns: true,
                    //                        width: 'auto',
                    //                        height: 500,
                    //                        //toolbar: '#searchBar',
                    //                        singleSelect: true,
                    //                        rownumbers: true,
                    //                        showFooter: true,
                    //                        onLoadSuccess: function(res) {
                    //                            if (res) {
                    //                                $(this).datagrid('mergeCells', {
                    //                                    index: res.total + 1,
                    //                                    field: 'ywy',
                    //                                    colspan: 2
                    //                                });
                    //                            }
                    //                        }
                    //                    });
                    $('#tb').datagrid('loadData', data);
                }
            }, "json");
        }

        function loadDataSuccess(res) {
            if (res) {
                $(this).datagrid('mergeCells', {
                    index: res.total + 1,
                    field: 'ywy',
                    colspan: 2
                });
            }
        }

        function initData() {
            $('#qSDate').datebox('setValue', DateFormatter(new Date().DateAdd('m', -1)));
            $('#qEDate').datebox('setValue', DateFormatter(new Date()));

            $.getJSON("JSONHandler.ashx?DataType=User", function(result) {
                $('#qBizMan').combogrid("grid").datagrid("loadData", result);
            });
        }

        function resetAll() {
            $('#fm').form('clear');
        }

        function openWin(url, title, width, height) {
            $('#winFrame').prop('src', url);
            $('#winFrame').prop('style').height = height + 'px';
            $('#winFrame').prop('style').width = width + 'px';
            $('#win').window({
                title: title,
                width: width + 'px',
                height: height + 'px',
                modal: true
            });
        }

        function fitTable() {
            $(".datagrid-header-inner").css("width", "100%");
            $(".datagrid-htable").css("width", "100%");
            $(".datagrid-footer-inner").css("width", "100%");
            $(".datagrid-btable").css("width", "100%");
            $(".datagrid-row").css("width", "100%");
            // $("table").css("table-layout", "fixed");
        }
        
        function viewOrder() {
            var row = $('#tb').datagrid('getSelected');
            if (row) {
                var id = row.OrderId;
                $('#winFrame').prop('src', 'EditOrderFrm.aspx?OrderId=' + id);
                $('#winFrame').prop('style').height = '100%';
                $('#winFrame').prop('style').width = '100%';
                $('#win').window({
                    fit: true,
                    modal: true,
                    resizable: true,
                    collapsible: false,
                    minimizable: false,
                    maximized: true,
                    title: '查看工作单'
                });
            }
        }      
    </script>

</head>
<body style="padding: 5px">
    <form id="form1" runat="server">
    </form>
    <div class="easyui-layout" fit="true">
        <div data-options="region:'north'" style="padding: 5px;">
            <form id="fm" style="padding: 0; margin: 0">
            <span>费用时段：</span>
            <input id="qSDate" class="easyui-datebox" data-options="formatter:DateFormatter,parser:DateParser"
                style="width: 90px" required="true" />至
            <input id="qEDate" class="easyui-datebox" data-options="formatter:DateFormatter,parser:DateParser"
                style="width: 90px" required="true" />
            <span>业务员：</span><input class="easyui-combogrid" id="qBizMan" style="width: 150px"
                data-options="  
            panelWidth: 150,  
            idField: 'id',  
            textField: 'userName',
            columns: [[   
                {field:'userName',title:'名称',width:150}               
            ]],  
            fitColumns: true  
        ">
            <a href="#" class="easyui-linkbutton" iconcls="icon-search" plain="true" onclick="doSearch();">
                搜索</a> <a href="#" class="easyui-linkbutton" iconcls="icon-undo" plain="true" onclick="resetAll();">
                    重置</a> <a href="#" class="easyui-linkbutton" iconcls="icon-ok" plain="true" onclick="exportExl();">
                        导出</a></form>
        </div>
        <div data-options="region:'center'" style="position: relative;">
            <table id="tb" class="easyui-datagrid" title="费用汇总" data-options="singleSelect:true,collapsible:false,url:'',fitColumns:true,fit:true,width:'auto',height:'auto',showFooter:true,rownumbers:true,onLoadSuccess:loadDataSuccess,onDblClickRow:viewOrder">
                <thead>
                    <tr>
                        <th data-options="field:'ywy'">
                            业务员
                        </th>
                        <th data-options="field:'gzdh'">
                            工作单号
                        </th>
                        <th data-options="field:'ysrmb'">
                            应收(人民币)
                        </th>
                        <th data-options="field:'yfrmb'">
                            应付(人民币)
                        </th>
                        <th data-options="field:'lrrmb'">
                            利润(人民币)
                        </th>
                        <th data-options="field:'ysmy'">
                            应收(美元)
                        </th>
                        <th data-options="field:'yfmy'">
                            应付(美元)
                        </th>
                        <th data-options="field:'lrmy'">
                            利润(美元)
                        </th>
                    </tr>
                </thead>
            </table>
        </div>
    </div>
    <div id="win">
        <iframe id="winFrame" src="" style="width: 0px; height: 0px" frameborder="0" scrolling="no">
        </iframe>
    </div>
</body>
</html>
